package rmmk.algorithms.features.fatures;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map.Entry;

import rmmk.algorithms.features.abstraction.AbstractFeatureExtractor;
import rmmk.algorithms.features.global.GlobalClassesWordCount;
import rmmk.framework.datasources.Document;

public class GlobalClassesWordCountExtractor extends AbstractFeatureExtractor {

	private int multip = 3;
	
	public GlobalClassesWordCountExtractor(int multiplier)
	{
		multip = multiplier;
	}
	
	@Override
	public Double[] doCalculate(Document document) {
		HashMap<String, ArrayList<String>> globalMap = GlobalClassesWordCount.getMap(multip);
		
		Double[] ret = new Double[getFeatureSize()];
		int counter = 0;
		
		for(Entry<String, ArrayList<String>> entry : globalMap.entrySet())
		{
			for(String s : entry.getValue())
				ret[counter++] = count(document, s);
		}
		
		return ret;
	}

	private Double count(Document document, String s) {
		int count = 0;
		
		for(String current : document.getExtractedWords())
			if(current.equals(s))
				++count;
		
		return (double) count;
	}

	@Override
	public int getFeatureSize() {
		return GlobalClassesWordCount.getMap(multip).size() * multip;
	}

}
